﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using A2DFramework.QueueService;
using A2DFramework.InstanceService;

namespace QueueConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            A2DFramework.Starter.Init();
            A2DFramework.QueueService.Starter.Init();

            IQueue srv = ObjectFactory.Resolve<IQueue>();

            //检查存储DTO1的队列是否存在，如不存在则自动建立
            srv.CreateIfNotExists<DTO1>();

            string msgId = "";
            DateTime from = DateTime.Now;
            int max = 5000;
            for (var i = 0; i < max; i++)
            {
                DTO1 o = new DTO1();
                o.p1 = "1";
                o.p2 = @"缺点是什么？

函数嵌套后，理解起来比较吃力
函数嵌套后，一行函数调用写成了很多行，很容易因为逗号、括号等造成语法错误
jQuery和liger在应用代码中强耦合，要是以后要更换UI框架，需要进行地毯式搜索...
 ";
                Message<DTO1> msg = new Message<DTO1>();
                msg.Body = o;
                srv.SendRequest2Worker<DTO1>(msg);
                msgId = msg.ID;
                if (i % 1000 == 0)
                    Console.Write(i+", ");
                //Console.WriteLine(msgId);
            }
            TimeSpan elapsed = DateTime.Now - from;
            Console.WriteLine();
            Console.WriteLine("Total time: "+elapsed.TotalSeconds);
            Console.WriteLine("TPS: " + max / elapsed.TotalSeconds);

            //DTO1 res=new DTO1();
            //res.p1 = "fffffff";
            //srv.SendResponse2Client<DTO1>(res, msgId);

            //DTO1 newMsg = null;
            //newMsg = srv.GetResponseFromWorker<DTO1>(msgId);
            //if(newMsg==null)
            //    Console.WriteLine("null");
            //else
            //    Console.WriteLine("not null");

            //newMsg = srv.GetResponseFromWorker<DTO1>(msgId);
            //if (newMsg == null)
            //    Console.WriteLine("null");
            //else
            //    Console.WriteLine("not null");

            Console.ReadKey();

            //while(true)
            //{
            //    newMsg = srv.GetRequestFromClient<DTO1>();
            //    if (newMsg != null)
            //        Console.WriteLine(newMsg.ID);
            //}
        }
    }

    public class DTO1 
    {
        public string p1 {get;set;}
        public string p2 { get; set; }
    }
}
